const AJAX = getApp().ajax,
      $wx = getApp().$wx,
      getColor = getApp().globalData.getColor;

Page({
  data: {
    getColor: getColor()
  },

  onLoad() {
    $wx.setNavColor(getColor().val);
  },

  onShow(){
    this.getAddList();    
  },

  /*删除*/ 
  Delete(e){
    let _this = this, id = e.detail.params.id;

    wx.showModal({
      title: '提示',
      content: '确认要删除该地址吗',
      success(res){
        if(res.confirm){
          _this.deleteAddress(id);
        }else if(res.cancel){
          _this.setData({
            slidingDeleteActive: false
          });
        }
      }
    })
  },

  /*获取列表*/
  getAddList(){
    let _this = this;
    wx.showNavigationBarLoading();

    AJAX.getAddList({},(status, data, msg)=>{
      wx.hideNavigationBarLoading();

      if(status){
        _this.setData({
          list: data || []
        });
      }else{
        $wx.showToast(msg);
      }
    });
  },

  /*删除地址*/
  deleteAddress(id){
    let _this = this;    
  
    AJAX.deleteAddress({id}, (status, data, msg) => {
      if (status) {
        _this.setData({
          slidingDeleteActive: false
        });
       _this.getAddList();
      } else {
        $wx.showToast(msg);
      }
    });
  }
});